package com.jinxin.platform.cdinfogo.task;

import com.jinxin.platform.base.common.pojo.JsonResult;
import com.jinxin.platform.cdinfogo.pojo.domain.CdinfogoDevice;
import com.jinxin.platform.cdinfogo.rpc.CdInfoGoRpcService;
import com.jinxin.platform.cdinfogo.service.CdinfogoDeviceService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;

import java.util.List;

/**
 * All rights Reserved, Designed By www.beonelot.com
 *
 * @version: V1.0
 * @Copyright: www.beonelot.com Inc. All rights reserved.
 * @Description：
 * @Date: 2021-12-20
 * @Author: Lingnan
 **/
@EnableScheduling
@Configuration
@Slf4j
public class InfogoScheduledTask {
    @Autowired
    private CdInfoGoRpcService cdInfoGoRpcService;
    @Autowired
    private CdinfogoDeviceService cdinfogoDeviceService;

    // 定期校正时间(每隔一小时)
    @Scheduled(cron = "0 0 0/1 * * ? ")
    public void adjustTime(){
        JsonResult jsonResult = cdinfogoDeviceService.queryAll(new CdinfogoDevice());
        if(jsonResult.getSuccess()){
            List<CdinfogoDevice> list = (List<CdinfogoDevice>) jsonResult.getData();
            for (int i = 0; i < list.size(); i++) {
                CdinfogoDevice device = list.get(i);
                cdInfoGoRpcService.adjustTime("",device.getDeviceMac());
            }
        }
    }
}
